import compression from "vite-plugin-compression";
import { Plugin } from "vite";

export default function createCompression(env:any): Plugin[] {
  const { VITE_BUILD_COMPRESS } = env;
  const compressList = VITE_BUILD_COMPRESS.split(",");
  const plugin: Plugin[] = [];
  if (compressList.includes("gzip")) {
    plugin.push(
      compression({
        ext: ".gz",
        deleteOriginFile: false,
        threshold: 50000,
        filter: (file:string) => /\.css$|\.js$/.test(file)
      }),
    );
  }
  // if (compressList.includes("brotli")) {
  //   plugin.push(
  //     compression({
  //       ext: ".br",
  //       algorithm: "brotliCompress",
  //       deleteOriginFile: false,
  //     }),
  //   );
  // }
  return plugin;
}
